package com.aaa.tmr.service.impl;

import com.aaa.tmr.service.CommonFileService;
import com.aaa.tmr.util.OssProperty;
import com.aaa.tmr.util.OssUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ：Marko
 * @date ：Created in 2021/3/23 22:52
 * @description ：公共文件处理接口实现类
 * @modified By：
 * @version:
 */
@Service
public class CommonFileServiceImpl implements CommonFileService {

    @Resource
    private OssProperty ossProperty;

    @Resource
    private OssUtil ossUtil;


    @Override
    public Map uploadFile(MultipartFile file, String savePath) {
        String path = ossUtil.uploadFile(file, savePath, ossProperty);
        Map returnMap = new HashMap();
        returnMap.put("fileName",file.getOriginalFilename());
        // 访问路径：https://aiops02bucket.oss-cn-beijing.aliyuncs.com/a/b/c/fdsfdsafasdfadsfawr.png
        returnMap.put("filePath",ossProperty.getUrl()+path);

        return returnMap;
    }
}
